﻿namespace RG.Common.Provider
{
    public interface IGenericDAO<TClass, TKey>
    {
        TClass Get(TKey id);
        TClass Put(TClass obj);
    }

    public interface IGenericDAO<TClass> : IGenericDAO<TClass, int>
    {
    }

    public class GenericDAO<TProvider, TClass, TKey> : TransactionService<TProvider>, IGenericDAO<TClass, TKey> 
        where TProvider: IDAOProvider
    {
        public TClass Get(TKey id)
        {
            return DAOSession.Get<TClass>(id);
        }

        public TClass Put(TClass obj)
        {
            DAOSession.Put(obj);
            return obj;
        }

        public TClass Insert(TClass obj)
        {
            DAOSession.Insert(obj);
            return obj;
        }

        public TClass Update(TClass obj)
        {
            DAOSession.Update(obj);
            return obj;
        }
    }

    public class GenericDAO<TProvider, TClass> : GenericDAO<TProvider, TClass, int>, IGenericDAO<TClass>
        where TProvider : IDAOProvider
    {
    }
}
